import 'dart:convert';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_yres/model/shop/hdk_list_model.dart';
import 'package:dio/dio.dart';
import 'package:flutter_yres/tool/constant.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_yres/tool/network/http_method.dart';
import 'package:flutter_yres/tool/network/http_url.dart';
import 'package:flutter_yres/pages/shop/shop_detail_page.dart';
import 'package:cached_network_image/cached_network_image.dart';
import './hdk_list_page.dart';
import 'SearchGoods.dart';

class HDKPage extends StatefulWidget {
  String type;
  String name;
  HDKPage({Key key, this.type, this.name}) : super(key: key);

  @override
  _HDKPageState createState() => _HDKPageState();
}

class _HDKPageState extends State<HDKPage> {
  TabController _tabController;
  List tabs = [
    {'name': '全部', 'cid': '0'},
    {'name': '车品', 'cid': '15'},
    {'name': '女装', 'cid': '1'},
    {'name': '男装', 'cid': '2'},
    {'name': '内衣', 'cid': '3'},
    {'name': '美妆', 'cid': '4'},
    {'name': '配饰', 'cid': '5'},
    {'name': '鞋品', 'cid': '6'},
    {'name': '箱包', 'cid': '7'},
    {'name': '儿童', 'cid': '8'},
    {'name': '母婴', 'cid': '9'},
    {'name': '居家', 'cid': '10'},
    {'name': '美食', 'cid': '11'},
    {'name': '数码', 'cid': '12'},
    {'name': '家电', 'cid': '13'},
    {'name': '其他', 'cid': '14'},
    {'name': '文体', 'cid': '16'},
    {'name': '宠物', 'cid': '17'},
  ]; //顶级分类数组
  @override
  Widget build(BuildContext context) {
    return new DefaultTabController(
        length: tabs.length,
        child: Scaffold(
          appBar: AppBar(
            title:
                Text(widget.name, style: TextStyle(fontSize: 18, color: black)),
            backgroundColor: white,
            brightness: Brightness.light,
            iconTheme: IconThemeData(color: black_99),
            elevation: 1.0,
            bottom: TabBar(
              labelColor: black,
              isScrollable: true,
              tabs: tabs.map((item) {
                return _tabsBuilder(context, item);
              }).toList(),
              controller: _tabController,
              onTap: (index) {
                // print(tabs[index].pdd_id);
              },
            ),
          ),
          body: new Column(
            children: <Widget>[
              new Container(
                child: new MaterialButton(
                  height: ScreenUtil.getInstance().setWidth(70),
                  child: Row(
                    children: <Widget>[
                      new Icon(Icons.search, color: Colors.grey),
                      new Text(
                        '点击搜索淘宝商品',
                        style: TextStyle(color: Colors.grey),
                      ),
                    ],
                  ),
                  onPressed: () {
                    Navigator.of(context)
                        .push(new MaterialPageRoute(builder: (context) {
                      return new SearchGoodsPage(type: '1');
                    }));
                  },
                  color: Colors.white,
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(20)),
                ),
                width: double.maxFinite,
                color: white,
                // height: kBottomNavigationBarHeight + 40,
                margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                padding: EdgeInsets.only(left: 10,right: 10),
              ),
              Expanded(
                  child: TabBarView(
                children: tabs.map<Widget>((item) {
                  // print(item.name);
                  // print(item.pdd_cat_id);
                  // print(item.pdd_id);
                  return HDKListPage(
                    type: widget.type,
                    name: widget.name,
                    cid: item['cid'],
                  );
                }).toList(),
              ))
            ],
          ),
        ));
  }

  Widget _tabsBuilder(BuildContext context, item) {
    return Tab(text: item['name']);
  }
}
